#coding=utf-8
__author__ = 'Administrator'

import web,time
import zipfile
from web.utils import storage
from config import TP_PATH


class ZIPoperator:
    def uploadFile(self):
        try:
            strBaseLocation=TP_PATH+"/static/tmpfiles"
            #需要在这里增加一个zip={}否则上传的文件名及大小等信息不会被保留
            x=web.input(zip={})
            nfilename=strBaseLocation+"/u_"+time.strftime("%Y%m%d%H%M%S")+".zip"
            #excel需要使用二进制写入打开参数需要wb
            fout=open(nfilename,'wb')
            fout.write(x["zip"].file.read())
            fout.close()
            return nfilename
        except :
            return None

    def extractall(self,filename):
        try:
            zf = zipfile.ZipFile(filename,"r")
            zf.extractall(TP_PATH+"/static/employeePic")
            return zf.filelist
        except :
            return None